//
//  SXNetWorkManager.m
//  NetEase-News
//
//  Created by 沈欣 on 2017/9/13.
//  Copyright © 2017年 沈欣. All rights reserved.
//

#import "SXNetWorkManager.h"

@implementation SXNetWorkManager

+ (instancetype)sharedManager {
    static SXNetWorkManager *instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURL *baseURL = [NSURL URLWithString:@"http://c.m.163.com/"];
        instance = [[self alloc] initWithBaseURL:baseURL];
        
        // 增加AFN支持的文件类型
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
    });

    return instance;
}


- (void)GETWithURLString:(NSString *_Nullable)URLString
              parameters:(nullable id)parameters
                 success:(void (^_Nullable)(id _Nullable responseObject))successBlock
                 failure:(void (^_Nullable)(NSError * _Nullable error))failureBlock {
    [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 把AFN获取到的数据,传递给外界
        if (successBlock) {
            successBlock(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}

@end
